<?php
/**
 * Created by PhpStorm.
 * User: deng
 * Date: 2016/11/8
 * Time: 14:25
 */
class AnonymousController {

    private $anonymousModel = null;
    private $diaryListCacheModel;

    function __construct(){
        $this->anonymousModel = new AnonymousModel();
        $this->diaryListCacheModel  =   new DiaryListCacheModel();
    }

    function callApi($param){
        $ac = trim($param['action']);
        if (!empty($ac)){
            $ac .= 'Action';
            return $this->{$ac}($param);
        }
        return $this->error($param);
    }

    function checkOpenStatus(){
        $time_0 = strtotime( date('Y-m-d 00:00:00') );
        $sec = AC::SERVER_TIME - $time_0;
        if ( ($sec>=AC::$anonymousOpenTime['start']) && ($sec<=AC::$anonymousOpenTime['end']) ){
            return true;
        }
        AC::$errorNo    =   'AYS010';//不在开放时间内
        AC::$errorMsg   =   AC::$anonymousOpenTime['not_allow_string'];
        return false;
    }

    private function checkFlashChatStatus(){
        $time_0 = strtotime( date('Y-m-d 00:00:00') );
        $sec = AC::SERVER_TIME - $time_0;
        if ( ($sec>=AC::$flashChatOpenTime['start']) && ($sec<=AC::$flashChatOpenTime['end']) ){
            return true;
        }
        AC::$errorNo    =   'AYS010';//不在开放时间内
        AC::$errorMsg   =   AC::$anonymousOpenTime['not_allow_string'];
        return false;
    }

    function checkUser($uid){
        $userService = new UserService();
        $user = $userService->getUserInfo($uid, AC::HOST_UID);
        if (!$user){
            return false;
        }
        if ( ($user['level']>=6) || $user['is_vip'] ){
            return true;
        }
        AC::$errorNo    =   'AYS011';//用户不能发送匿名卡片
        //AC::$errorMsg   =   'Hi！六级及其以上用户 or VIP用户就可以发布匿名啦';
        AC::$errorMsg   =   '六级以上用户才能发表评论哦~';
        return false;
    }

    /*function testArr(){
        $str = file_get_contents('d:/aabb.txt');//将整个文件内容读入到一个字符串中
        
        $str_encoding = mb_convert_encoding($str, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5');//转换字符集（编码）
        $arr = explode("\r\n", $str_encoding);//转换成数组
        $arr2 = array();
        $i = 11001;
        //去除值中的空格
        foreach ($arr as $k => $v) {
            //$row = trim($row);
            $arr2[$i] = $v;
            $i++;
        }
        $aaa = '';
        foreach ($arr2 as $key => $val) {
            $aaa .= "'".$key."' => "."'".$val."', ";
        }
        
        print_r($aaa);
    }*/

    function postCardAction($param){
        $uid = AC::HOST_UID;
        $this->checkOpenStatus();
        if (AC::$errorNo){
            return false;
        }
        $this->checkUser($uid);
        if (AC::$errorNo){
            return false;
        }
        $param['content'] = UK::getstr($param['content'], 500);
        $content_len = mb_strlen($param['content'], 'UTF-8');
        if ($uid<1 || $content_len<1 || $content_len>80){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        $param['uid'] = $uid;
        $diaryListModel = new DiaryListModel();
        // 判别是否重复提交
        $ck = $diaryListModel->checkLastContent($param);
        if (AC::$errorNo){
            UK::varDump(AC::$errorNo, __METHOD__);//DC110
            return  FALSE;
        }
        $param['attachment'] = 0;
        if(isset($param['avatar'])){
            if($param['avatar'] >= 50 || $param['avatar'] < 0){
                AC::$errorNo    =   'AYS001';//参数不符合要求
                return  false;
            }
        }else{
            $param['avatar'] = $this->anonymousModel->makeUidAnonymousAvatar();
        }
        if(isset($param['nickname'])){
            if(!$this->anonymousModel->checkNicknameByCode($param['nickname'])){
                AC::$errorNo    =   'AYS001';//参数不符合要求
                return  false;
            }
        }else{
            $param['nickname'] = $this->anonymousModel->makeUidAnonymousNickname();
        }
        /*$param['avatar'] = $this->anonymousModel->makeUidAnonymousAvatar();
        $param['nickname'] = $this->anonymousModel->makeUidAnonymousNickname();*/
        $result = $this->anonymousModel->addAnonymous($param);
        if ($result){
            $this->anonymousModel->addAnonymous2NewList($result, $uid);
            $diaryListCacheModel = new DiaryListCacheModel();
            $diaryListCacheModel->setLastCheckConnent($uid, $ck);
            return true;
        }
        return false;
    }

    public function postAutoCardAction($param){
        if ($param['uid']<1){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        $diaryListModel = new DiaryListModel();
        // 判别是否重复提交
        $ck = $diaryListModel->checkLastContent($param);
        if (AC::$errorNo){
            return  FALSE;
        }
        $param['attachment'] = 0;
        $result = $this->anonymousModel->addAnonymous($param);
        if ($result){
            $this->anonymousModel->addAnonymous2NewList($result, $param['uid']);
            $diaryListCacheModel = new DiaryListCacheModel();
            $diaryListCacheModel->setLastCheckConnent($param['uid'], $ck);
            return $result;
        }
        return false;
    }

    public function postAutoCommentAction($param){
        if ($param['uid']<1){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }

        if($this->diaryListCacheModel->isUidRemoving($param['uid'])){
            AC::$errorNo    =   'AYS002';//该用户被封禁
            return  false;
        }
        $card = $this->anonymousModel->getAnonymousInfoByBodyId($param['bodyId']);
        if (AC::$errorNo){
            return false;
        }

        $result = $this->anonymousModel->addComment($param);
        if ($result){
            $this->diaryListCacheModel->setAnonyCheckConnent($param['uid'], $param['bodyId'], $param['content']);
            $set = ['comment'=>$result];
            $this->anonymousModel->updateAnonymous(['uid'=>$card['uid'], 'bodyId'=>$param['bodyId']], $set);

            //发送评论成功，调用im服务器为弹幕服务
            $this->addImMessage($param['uid'], "anonymous_".$param['bodyId'], $param['nickname'], $param['content']);
            return true;
        }
        return false;
    }

    function cardAction($param){
        $bodyid = intval($param['bodyId']);
        if ($bodyid<1000){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        $info = $this->anonymousModel->getAnonymousInfoByBodyId($bodyid);
        if (AC::$errorNo){
            return false;
        }
        $info = $this->assemblyAnonymousItem($info);
        return [ 'card'=>$info ];
    }

    /**
    *   获取最新的一条闪聊
    */
    function recentCardAction($param){
        $this->checkFlashChatStatus();
        if (AC::$errorNo){
            AC::$errorNo    =   null;//不在开放时间内
            AC::$errorMsg   =   '';
            return [ 'card'=>[]];
        }

        //$info = $this->anonymousModel->getNewAnonymousInfo();
        $info = $this->anonymousModel->getNewAnonymousInfoByUid(2);
        $info = $this->assemblyAnonymousItem($info);
        return [ 'card'=>$info ];
    }

    function deleteCardAction($param){
        $param['uid'] = intval($param['uid']);
        $param['bodyId'] = intval($param['bodyId']);
        if ($param['bodyId']<1000 || $param['uid']<1 || $param['uid']!=HOST_UID){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        $info = $this->anonymousModel->getAnonymousInfoByBodyId($param['bodyId']);
        if (AC::$errorNo){
            return false;
        }
        if($param['uid']!=$info['uid']){
            AC::$errorNo = 'AYS003';//不是自己的卡片
            return false;
        }
        $set = ['status'=>1];
        $result = $this->anonymousModel->updateAnonymous($param, $set);
        return $result ? true : false;
    }

    /**
    *   点赞评论
    */
    function likeAction($param){
        $param['uid'] = intval($param['uid']);
        $param['bodyId'] = intval($param['bodyId']);
        $param['position'] = $param['position'];
        if ($param['bodyId']<1000 || $param['uid']<1 || $param['uid']!=HOST_UID || !isset($param['position'])){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        $param['type'] = trim($param['type']);
        !in_array($param['type'], ['like', 'dislike']) && $param['type'] = 'like';
        $likeInfo = $this->anonymousModel->getFavoriteInfoByBodyId($param['bodyId'], $param['uid'], $param['position']);
        if ($param['type']=='like' && $likeInfo){
            AC::$errorNo    =   'AYS004';//已经点赞过了
            return  false;
        }
        if ($param['type']=='dislike' && !$likeInfo){
            AC::$errorNo    =   'AYS005';//还没点赞
            return  false;
        }
        $info = $this->anonymousModel->getCommentInfoByBodyIdPos($param['bodyId'], $param['position']);
        if($param['position'] == 0){
            $info = $this->anonymousModel->getAnonymousInfoByBodyId($param['bodyId']);
        }
        if (AC::$errorNo){
            return false;
        }
        $info['favorites'] = $param['type']=='like' ? intval($info['favorites'])+1 : intval($info['favorites'])-1;
        $info['favorites']<0 && $info['favorites'] = 0;
        $set = ['favorites'=>$info['favorites']];
        $where = [ 'uid'=>$info['uid'], 'bodyId'=>$param['bodyId'] ];
        if($param['position'] == 0){
            $result = $this->anonymousModel->updateAnonymous($where, $set);
        }else{
            $where['pos'] = $param['position'];
            $result = $this->anonymousModel->updateComment($where, $set);
        }
        
        if ($result){
            $param['type']=='like'
                ?
            $this->anonymousModel->addFavorite($param)
                :
            $this->anonymousModel->removeFavorite($param['bodyId'], $param['uid'], $param['position']);
        }
        return $result ? true : false;
    }

    /**
    *  进入写小纸条界面生成随机头像和昵称
    */
    function getNameAndAvatarAction($param){
        $result = [];
        $result['avatar'] = $this->anonymousModel->makeUidAnonymousAvatar();
        $result['avatarStr'] = $this->anonymousModel->anonymousAvatarCode2String($result['avatar']);
        $result['nickname'] = $this->anonymousModel->makeUidAnonymousNickname();
        $result['nicknameStr'] = $this->anonymousModel->anonymousNicknameCode2String($result['nickname']);
        return $result;
    }

    function anonymousListAction($param){
        $this->checkOpenStatus();
        if (AC::$errorNo){
            AC::$errorNo    =   null;//不在开放时间内
            AC::$errorMsg   =   '';
            return [ 'list'=>[], 'count'=>0, 'official'=>['showPos' => '-1', 'list' => [] ]  ];;
        }
        $uid = intval($param['uid']);
        $type = trim($param['type']);
        !in_array($type, ['me', 'new', 'hot']) && $type = 'me';
        if ($type=='me' && $uid<1 && $uid!=HOST_UID){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        list($id, $start, $length) = UK::assemblePageData($param);
        switch ($type){
            case 'me':$list = $this->anonymousModel->userAnonymousList($uid, $id, $length);break;
            case 'new':$list = $this->anonymousModel->newAnonymousList($param);break;
            case 'hot':$list = $this->anonymousModel->hotAnonymousList($id, $length);break;
            default:$list = [];break;
        }
        $result = [];
        foreach ($list as $item){
            $item = $this->assemblyAnonymousItem($item);
            $item && $result[] = $item;
        }
        $ret = [ 'list'=>$result, 'count'=>count($result) ];
        if ($type=='hot'){
            $official = $this->anonymousModel->officialAnonymous();
            if (!empty($official['list'])){
                foreach ($official['list'] as &$v){
                    $v = $this->assemblyAnonymousItem($v);
                    $v['action'] = 'pinksns://anonymous/post';
                }
            }
            $ret['official'] = $official;
        }
        return $ret;
    }

    function assemblyAnonymousItem($item){
        if (empty($item))return[];
        $item['nickname'] = $this->anonymousModel->anonymousNicknameCode2String( $item['nickname'] );
        $item['avatar'] = $this->anonymousModel->anonymousAvatarCode2String( $item['avatar'] );
        $item = array_merge($item, $this->anonymousModel->parseAnonymousExtraField($item['extra']));
        $item['bodyId'] = $item['id']*1000 + UK::getHashId($item['uid'], 32);
        $position = isset($item['position']) ? $item['position'] : 0;
        $like = AC::HOST_UID ? $this->anonymousModel->getFavoriteInfoByBodyId($item['bodyId'], AC::HOST_UID, $position) : false;
        $item['melike'] = $like ? true : false;
        //$item['melike'] = false;
        $item['is_me'] = $item['uid']==AC::HOST_UID ? true : false;
        unset($item['extra']);
        unset($item['uid']);
        unset($item['attachment']);
        return $item;
    }

    function postCommentAction($param){
        $this->checkOpenStatus();
        if (AC::$errorNo){
            return false;
        }
        $uid = AC::HOST_UID;
        $param['content'] = UK::getstr($param['content'], 500);
        $content_len = mb_strlen($param['content'], 'UTF-8');
        $param['bodyId'] = intval($param['bodyId']);
        $param['bgUrl'] = intval($param['bgUrl']);
        if ($uid<1 || $content_len<1 || $content_len>140 || $param['bodyId']<1000){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        if($this->diaryListCacheModel->isUidRemoving($uid)){
            AC::$errorNo    =   'AYS002';//该用户被封禁
            return  false;
        }
        /*if(AC::$anonymousCommentVerdion){
            $this->checkUser($uid);
            if (AC::$errorNo){
                return false;
            }
        }*/
        $card = $this->anonymousModel->getAnonymousInfoByBodyId($param['bodyId']);
        if (AC::$errorNo){
            return false;
        }
        //判断是否重复提交
        $content = md5($param['content']);
        $repetContent = $this->anonymousModel->checkCommentRepet($uid, $param['bodyId'], $content);
        if (AC::$errorNo){
            return false;
        }

        $param['parentId'] = intval($param['pos']);
        if ($param['parentId']>0){
            $p_info = $this->anonymousModel->getCommentInfoByBodyIdPos($param['bodyId'], $param['parentId']);
            if (!$p_info){
                AC::$errorNo    =   'AYS006';//引用回复不存在
                return  false;
            }
            if ($p_info['uid']==$uid){
                AC::$errorNo    =   'AYS007';//不能回复自己的评论
                return  false;
            }
        }else{
            $param['parentId'] = 0;
        }
        if ($card['uid']==$uid){//是自己的卡片
            $param['avatar'] = $card['avatar'];
            $param['nickname'] = $card['nickname'];
        }else{
            $myComment = $this->anonymousModel->getCommentInfoByBodyIdUid($param['bodyId'], $uid, 1);
            if ($myComment){//曾经回复过
                $param['avatar'] = $myComment['avatar'];
                $param['nickname'] = $myComment['nickname'];
            }else{//第一次回复
                $param['avatar'] = $this->anonymousModel->makeUidAnonymousAvatar($card['avatar']);
                $param['nickname'] = $this->anonymousModel->makeUidAnonymousNickname($card['nickname']);
            }
        }
        $param['attachment'] = 0;
        $param['uid'] = $uid;
        $result = $this->anonymousModel->addComment($param);
        if ($result){
            $this->diaryListCacheModel->setAnonyCheckConnent($uid, $param['bodyId'], $content);
            $post_position = $result;
            $param['id'] = $result;
            $param['card'] = $card;
            $param['new_pos'] = $result;
            $param['p_info'] = isset($p_info)?$p_info:[];
            $this->postCommentSuccessEvent($param);
            $new = $this->anonymousModel->getCommentInfoByBodyIdPos($param['bodyId'], $post_position);
            if ($new){
                $new = $this->assemblyCommentItem($new);
                return [
                    'comment' => [$new],
                    'count' => 1
                ];
            }
        }
        return false;
    }

    private function addImMessage($uid, $gid, $nickname, $content){
        $chatGroupService = new ChatGroupService();
        $data = ['avatar'=>$nickname,'uid'=>$uid,'content'=>$content,'id'=>'0','muid'=>'','msgType'=>'','time'=>AC::SERVER_TIME,'voice'=>[],'type'=>'1','attachment'=>[]];
        $chatGroupService->sendMsg2GroupQueue($uid, $gid, $data);
    }

    function deleteCommentAction($param){
        $param['uid'] = intval($param['uid']);
        $param['bodyId'] = intval($param['bodyId']);
        $param['pos'] = intval($param['pos']);
        if ($param['bodyId']<1000 || $param['uid']<1 || $param['uid']!=AC::HOST_UID || $param['pos']<1){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        $info = $this->anonymousModel->getCommentInfoByBodyIdPos($param['bodyId'], $param['pos']);
        if (empty($info)){
            AC::$errorNo    =   'AYS008';//评论不存在
            return  false;
        }
        $info['bodyid'] = $info['cid'];
        if ($info['uid']!=$param['uid']){
            AC::$errorNo    =   'AYS009';//不能删除别人的评论
            return  false;
        }
        $set = ['status'=>1];
        $result = $this->anonymousModel->updateComment($param, $set);
        if ($result){
            //删除匿名作者收到的评论通知
            $anonymous = $this->anonymousModel->anonymousInfo($info['bodyid']);
            if ($anonymous){
                $this->anonymousModel->flagMessageDelByBodyidPos($anonymous['uid'], $info['bodyid'], $info['position']);
            }
            //删除被引用楼层收到的评论通知
            if ($info['parentId']>0){
                $p_info = $this->anonymousModel->getCommentInfoByBodyIdPos($info['bodyid'], $info['parentId']);
                if (AC::$errorNo){
                    AC::$errorNo = null;
                }else{
                    $this->anonymousModel->flagMessageDelByBodyidPos($p_info['uid'], $info['bodyid'], $info['position']);
                }
            }
        }
        return $result ? true : false;
    }

    function commentAction($param){
        $param['bodyId'] = intval($param['bodyId']);
        $param['uid'] = intval($param['uid']);
        if ($param['bodyId']<1000 || $param['uid']<0){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        list($id, $start, $length) = UK::assemblePageData($param);
        $list = $this->anonymousModel->getCommentListByBodyId($param['bodyId'], $id, $length);
        !$list && $list = [];
        foreach ($list as &$item){
            $item = $this->assemblyCommentItem($item);
        }
        return [ 'comment'=>$list, 'count'=>count($list) ];
    }

    function commentNewAction($param){
        $param['bodyId'] = intval($param['bodyId']);
        $param['uid'] = intval($param['uid']);
        $param['sort'] = isset($param['sort']) ? $param['sort'] : 'down';
        if ($param['bodyId']<1000 || $param['uid']<0){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        list($id, $start, $length) = UK::assemblePageData($param);
        $list = $this->anonymousModel->getCommentListByBodyId($param['bodyId'], $id, $length, $param['sort']);
        !$list && $list = [];
        foreach ($list as &$item){
            $item = $this->assemblyCommentItem($item);
        }
        return [ 'comment'=>$list, 'count'=>count($list) ];
    }

    /**
    *   获取单条评论详情
    */
    function getCommentAction($param){
        $param['bodyId'] = intval($param['bodyId']);
        $param['position'] = intval($param['position']);
        if ($param['bodyId']<1000 || $param['position']<1){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        $commentInfo = $this->anonymousModel->getCommentInfoByBodyIdPos($param['bodyId'], $param['position']);
        if (AC::$errorNo){
            return false;
        }
        $commentInfo = $this->assemblyCommentItem($commentInfo);
        return $commentInfo;
    }

    function assemblyCommentItem($item, $deep=1){
        $item['nickname'] = $this->anonymousModel->anonymousNicknameCode2String( $item['nickname'] );
        $item['avatar'] = $this->anonymousModel->anonymousAvatarCode2String( $item['avatar'] );
        $item['parent_detail'] = (object)[];
        if ($item['parentId'] && $deep){//$deep是否参与递归
            $info = $this->anonymousModel->getCommentInfoByBodyIdPos($item['cid'], $item['parentId']);
            $info && $item['parent_detail'] = $this->assemblyCommentItem($info, 0);
        }
        $like = AC::HOST_UID ? $this->anonymousModel->getFavoriteInfoByBodyId($item['cid'], AC::HOST_UID, $item['position']) : false;
        $item['melike'] = $like ? true : false;
        $item['is_me'] = $item['uid']==AC::HOST_UID ? true : false;
        $item['bodyId'] = $item['cid'];
        if($this->diaryListCacheModel->isUidRemoving($item['uid'])) $item['content'] = '该内容已被屏蔽';
        unset($item['uid'], $item['cid']);
        return $item;
    }

    function postCommentSuccessEvent($param){
        $userStacModel = new UserStatisticsModel();
        $bodyid = $param['bodyId'];
        $card = $param['card'];
        $card['comment']++;
        $set = ['comment'=>$param['new_pos']];
        $this->anonymousModel->updateAnonymous(['uid'=>$card['uid'], 'bodyId'=>$bodyid], $set);
        if ($card['uid']!=$param['uid']){//通知匿名楼主
            if(empty($param['parentId']) || $param['p_info']['uid'] == $card['uid']){
                $this->anonymousModel->addMessage([
                    'uid' => $card['uid'],
                    'bodyId' => $bodyid,
                    'position' => $param['new_pos'],
                    'rUid' => $param['uid'],
                    'avatar' => $param['avatar'],
                    'nickname' => $param['nickname'],
                    'type' => 0,
                    'content' => $param['content']
                ]);
                $userStacModel->updateUserStatisticsByUid($card['uid'], ['aysCommentTimes'=>1]);
            }
//            $this->pushAnonymousComment($param['uid'], 0, $card['uid'], 0, $param['new_pos'], $param['content']);
        }
        if (!empty($param['p_info']) && $param['p_info']['uid']!=$card['uid']){//通知匿名引用楼层
            $pInfo = $param['p_info'];
            $this->anonymousModel->addMessage([
                'uid' => $pInfo['uid'],
                'bodyId' => $bodyid,
                'position' => $param['new_pos'],
                'rUid' => $param['uid'],
                'avatar' => $param['avatar'],
                'nickname' => $param['nickname'],
                'type' => 0,
                'content' => $param['content']
            ]);
            $userStacModel->updateUserStatisticsByUid($pInfo['uid'], ['aysCommentTimes'=>1]);
//            $this->pushAnonymousComment($param['uid'], $pInfo['uid'], $card['uid'], $param['parentId'], $param['new_pos'], $param['content']);
        }
    }

    function messageAction($param){
        $uid = AC::HOST_UID;
        if ($uid<1){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        list($id, $start, $length) = UK::assemblePageData($param);
        $list = $this->anonymousModel->getMessageList($uid, $id, $length);
        !$list && $list = [];
        foreach ($list as &$item){
            $item['avatar'] = $this->anonymousModel->anonymousAvatarCode2String($item['avatar']);
            $item['nickname'] = $this->anonymousModel->anonymousNicknameCode2String($item['nickname']);
            $bodyid = $item['bodyid'];
            unset($item['uid'], $item['rUid'], $item['bodyid']);
            $item['bodyId'] = $bodyid;
        }
        if (!$id){
            //重置匿名通知计数
            $userStacModel = new UserStatisticsModel();
            $userStacModel->resetAysCommentTimesStatistics($uid);
        }
        return [ 'list'=>$list, 'count'=>count($list) ];
    }

    function removeMessageAction($param){
        $uid = AC::HOST_UID;
        $id = intval($param['id']);
        $ids = trim($param['ids']);
        if ($uid<1){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        $type = in_array(trim($param['type']), ['id', 'ids', 'all']) ? trim($param['type']) : 'id';
        if ($type=='id' && $id<1){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        if ($type=='ids' && empty($ids)){
            AC::$errorNo    =   'AYS001';//参数不符合要求
            return  false;
        }
        switch ($type){
            case 'id':
                $result = $this->anonymousModel->removeMessage($uid, $id);
                break;
            case 'ids':
                $ids_arr = explode(',', $ids);
                foreach ($ids_arr as &$id){
                    $id = intval($id);
                }
                $ids = implode(',', $ids_arr);
                $result = $this->anonymousModel->removeidsMessage($uid, $ids);
                break;
            case 'all':
                $result = $this->anonymousModel->clearMessage($uid);
                break;
            default:$result = true;break;
        }
        return $result ? true : false;
    }

    function pushAnonymousComment($fromUid, $rUid, $author_uid, $parentId, $position, $content)
    {
        $pushService = new PushService();

        $host_uid = AC::HOST_UID;
        $action  = 'pushAnonymousComment';
        $data = array(
            'uid'           =>    $fromUid,
            'rUid'          =>    $rUid,
            'author_uid'    =>    $author_uid,
            'parentId'      =>    $parentId,
            'position'      =>    $position,
            'content'       =>    $content
        );

        $toUid = $parentId > 0 ? $rUid : $author_uid;
        return $pushService->pushToRedisList($data, $action, $toUid, $host_uid);
    }

    function __call($name, $arguments){
        AC::$errorNo    =   'SA004';
        return  ' Error : call do is not exists in AnonymousController! ';
    }

}